//player sideChat "Infguard loaded";
_leader = _this select 0;
_pos = nil;	// Make sure the scope is for the whole script
//player sideChat Format["Leader is %1", _leader];
if (alive _leader) then {
	player sideChat "leader is alive, proceeding";
	_pos = getpos _leader;
	_flags = nearestObjects [_pos, ["FlagCarrier"], 1500];

	if (count _flags > 0) then {
		_flag = _flags select 0;	
		_pos = getpos _flag;
		player sideChat Format["Found the flag at %1", _pos];
		if (_leader distance _flag >= 150) then
		{
			player sideChat "Moving towards the flag!";
			group _leader setBehaviour "AWARE";
			group _leader setFormation "VEE";
			group _leader move getpos _flag;
			hint "assaulting the flag";
			sleep 3;
		};
	};
};
waituntil {unitReady _leader};
player sideChat "Finished moving to the flag";
sleep (random 60);
while {alive _leader} do
{
	_x = random 150 - random 500;
	_y = random 150 - random 500;
	//player sideChat Format["_pos is %1", _pos];
	_movePos = [(_pos select 0) + _x,(_pos select 1) + _y,0];
	"patrol" setMarkerPos [_movePos select 0, _movePos select 1];
	group _leader setBehaviour "SAFE";
	group _leader setFormation "FILE";
	group _leader move _movePos;
	_leader sideChat Format["moving patrol to %1", _movePos];
	sleep 3;
	waituntil {unitReady _leader};
	leader group _leader sideChat "PAtrol WP Done";
};
